package com.de.juxfux.juxfeuer;

import java.util.Locale;

import com.de.juxfux.settings.SettingsActivity;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.widget.Toast;


public class JuxVoice extends Service implements OnInitListener {
	public static TextToSpeech tts;

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		tts = new TextToSpeech(this, this);
		return super.onStartCommand(intent, flags, startId);
	}

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	public void onInit(int status) {
		if (status == TextToSpeech.SUCCESS) {
			if (tts.isLanguageAvailable(Locale.GERMANY) >= 0) {
				Toast.makeText(this, "TTS-engine 'JuxVoice' erfolgreich initialisiert.", Toast.LENGTH_LONG).show();
				tts.setLanguage(Locale.GERMANY);
				tts.setPitch(SettingsActivity.getSpeechPitch(this));
				tts.setSpeechRate(SettingsActivity.getSpeechRate(this));
			}
		} else if (status == TextToSpeech.ERROR) {
			Toast.makeText(this, "Fehler! TTS-engine 'JuxVoice' konnte nicht initialisiert werden!", Toast.LENGTH_LONG).show();
		}
	}

	@Override
	public void onDestroy() {
		if (tts != null) {
			tts.shutdown();
		}
		super.onDestroy();
	}

}
